# 数据采集的时候，绕过登录，然后进入某个页面！

import urllib.request

url = 'https://weibo.com/u/6126208218'

headers = {
    "cookie": 'SINAGLOBAL=4389201594668.568.1742562095974; ULV=1742562096020:1:1:1:4389201594668.568.1742562095974:; XSRF-TOKEN=qmy-b4kPILMwDhDaOSpYzKxn; SCF=AkSciCoOLvoi4GR8a9Ollq4WlOF22vE7z9KnCEAXfTmZcMM5AXHKgnY9oLkEZdN-1jmHll0-r2qOOwK3Sj1Qlcc.; SUB=_2A25K558rDeRhGeBP6VQT8CbOyjSIHXVpnJ7jrDV8PUNbmtAYLU_nkW9NRWc3zSkjj-N-4F8OVctxsPpvkD_CeoLr; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9W5nf.-H.afoy7X-TJeKEiu05JpX5KzhUgL.FoqpeoqEehnEeKn2dJLoIp7LxKBLB.zL1h._i--fi-zEi-24i--fi-zEi-24; ALF=02_1745583227; WBPSESS=SdNjAm69kt0J8TnnXl_t4_5lvAEWlTRE6gYY5ADqcqol7a4O-MBDdZeGTe0Zd4LKeYbLGXGGOCVLAt_alylLQt0CYNLoQTp5tsUwaBhhmQcVpLQWQsEvB0HXPWp-fyZ9NePw6-gub_ItXIUAlyV7-A==',
    # 图的防盗链
    "referer": 'https://weibo.com/newlogin?tabtype=weibo&gid=102803&openLoginLayer=0&url=https%3A%2F%2Fweibo.com%2F'
}


# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(request)

# 获取响应数据
context = response.read().decode('utf-8')
# context = response.read().decode('gb2312')

# print(context)
# with open('weibo.html', 'w', encoding='gb2312',) as fp:
with open('weibo.html', 'w', encoding='utf-8',) as fp:
    fp.write(context)